/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cardgame.gui;

import cardgame.*;

/**
 *
 * @author Carl
 */
public class GUITest extends javax.swing.JFrame{

    public GUITest(CommandSender commandSender){
        initComponents();
        FrameUtil.initWindowSpecials(this);
        setSize((int) ((2100.0 / 2400) * 1035), 1035);
        setLocation(((1920 - getWidth()) / 2), 0);
        setTitle(GameInfo.NAME);
        panField = new PanField(commandSender, cardInfoFrame);
        panFieldContainer.add(panField);
        updateCardInfoFrameLocation();
        cardInfoFrame.setVisible(true);
        new Thread(new Runnable(){

            @Override
            public void run(){
                long lastFrameTimestamp = System.currentTimeMillis();
                while(true){
                    long currentTimestamp = System.currentTimeMillis();
                    float lastTimePerFrame = ((currentTimestamp - lastFrameTimestamp) / 1000f);
                    lastFrameTimestamp = currentTimestamp;
                    panField.update(lastTimePerFrame);
                    try{
                        Thread.sleep(1000 / 60);
                    }catch(InterruptedException ex){
                    }
                }
            }
        }).start();
    }
    private PanField panField;
    private CardInfoFrame cardInfoFrame = new CardInfoFrame();
    
    private void updateCardInfoFrameLocation(){
        cardInfoFrame.setLocation((int) (getLocation().getX() - cardInfoFrame.getWidth()), (int) (getLocation().getY() + getHeight() - cardInfoFrame.getHeight()));
    }

    public PanField getPanField(){
        return panField;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panFieldContainer = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentMoved(java.awt.event.ComponentEvent evt) {
                formComponentMoved(evt);
            }
        });

        panFieldContainer.setLayout(new java.awt.GridLayout(1, 0));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panFieldContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 632, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panFieldContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 724, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentMoved(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentMoved
        updateCardInfoFrameLocation();
    }//GEN-LAST:event_formComponentMoved

    private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
        cardInfoFrame.toFront();
    }//GEN-LAST:event_formWindowGainedFocus
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel panFieldContainer;
    // End of variables declaration//GEN-END:variables
}
